<template>
    <el-dialog
            :title="!dataForm.orderId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="任务ID" prop="taskId">
                        <el-input v-model="dataForm.taskId" placeholder="任务ID"></el-input>
                </el-form-item>
                <el-form-item label="分配的设备ID" prop="equipmentId">
                        <el-input v-model="dataForm.equipmentId" placeholder="分配的设备ID"></el-input>
                </el-form-item>
                <el-form-item label="分配的操作人员ID" prop="operatorId">
                        <el-input v-model="dataForm.operatorId" placeholder="分配的操作人员ID"></el-input>
                </el-form-item>
                <el-form-item label="分配的工位ID" prop="workstationId">
                        <el-input v-model="dataForm.workstationId" placeholder="分配的工位ID"></el-input>
                </el-form-item>
                <el-form-item label="任务开始时间" prop="startTime">
                        <el-date-picker
                                v-model="dataForm.startTime"
                                type="datetime"
                                placeholder="任务开始时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="任务结束时间" prop="endTime">
                        <el-date-picker
                                v-model="dataForm.endTime"
                                type="datetime"
                                placeholder="任务结束时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="是否批量分配" prop="batchAllocation">
                        <el-input v-model="dataForm.batchAllocation" placeholder="是否批量分配"></el-input>
                </el-form-item>
                <el-form-item label="是否单独调整" prop="individualAdjustment">
                        <el-input v-model="dataForm.individualAdjustment" placeholder="是否单独调整"></el-input>
                </el-form-item>
                <el-form-item label="工艺要求" prop="processRequirements">
                        <el-input v-model="dataForm.processRequirements" placeholder="工艺要求"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
        data () {
            return {
                visible: false,
                dataForm: {
                    id: null,
                    taskId: null,
                    equipmentId: null,
                    operatorId: null,
                    workstationId: null,
                    startTime: null,
                    endTime: null,
                    batchAllocation: null,
                    individualAdjustment: null,
                    processRequirements: null,
                },
                dataRule: {
                    id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
                    ],
                    taskId: [
                        { required: true, message: '任务ID不能为空', trigger: 'blur' }
                    ],
                    equipmentId: [
                        { required: true, message: '分配的设备ID不能为空', trigger: 'blur' }
                    ],
                    operatorId: [
                        { required: true, message: '分配的操作人员ID不能为空', trigger: 'blur' }
                    ],
                    workstationId: [
                        { required: true, message: '分配的工位ID不能为空', trigger: 'blur' }
                    ],
                    startTime: [
                        { required: true, message: '任务开始时间不能为空', trigger: 'blur' }
                    ],
                    endTime: [
                        { required: true, message: '任务结束时间不能为空', trigger: 'blur' }
                    ],
                    batchAllocation: [
                        { required: true, message: '是否批量分配不能为空', trigger: 'blur' }
                    ],
                    individualAdjustment: [
                        { required: true, message: '是否单独调整不能为空', trigger: 'blur' }
                    ],
                    processRequirements: [
                        { required: true, message: '工艺要求不能为空', trigger: 'blur' }
                    ],
                }
            }
        },
        methods: {
            init (id) {
                this.dataForm.orderId = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    this.dataForm.orderId = id || 0
                    if (this.dataForm.orderId) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppProductionScheduling/info/\\$\\{this.dataForm.orderId}`),
                            method: 'get',
                            params: this.$http.adornParams()
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.dataForm = data.appproductionscheduling
                            }
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit () {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl(`/app/AppProductionScheduling/\\$\\{!this.dataForm.orderId ? 'save' : 'update'}`),
                            method: 'post',
                            data: this.$http.adornData(this.dataForm)
                        }).then(({data}) => {
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refreshDataList')
                                    }
                                })
                            } else {
                                this.$message.error(data.msg)
                            }
                        })
                    }
                })
            }
        }
    }
</script>